Skip to content

Fix user group reads failing when a member's stored role is None or Tenant Admin - #2100

Merged
mnoszczak merged 1 commit into
developfrom
mnoszczak/plt-3830-list-groups-none-role
Nov 25, 2026
Merged

mnoszczak merged 1 commit into
developfrom
mnoszczak/plt-3830-list-groups-none-role

Conversation

@mnoszczak

Copy link
Copy Markdown
Contributor

Description

Before: reading user groups failed when a group had a member whose stored role is None or Tenant Admin. UserGroup.get_user_groups(), UserGroup.get(), UserGroup.list_members() and the reads at the end of create() and update() raised:

ValueError: Role 'NONE' cannot be assigned to UserGroup members. UserGroup members cannot have 'NONE' roles.

One such member was enough to stop a workspace from listing any of its groups.

Now: these calls return the group, and the member comes back with the role stored for it.

Why it happened: UserGroupMember.__post_init__ refuses the roles NONE and TENANT_ADMIN. That check is meant for members a caller builds before adding them to a group. The SDK also ran it when it built members from a server response in UserGroup._get_members_set, so data that already exists on the server made every read fail.

The fix: members read from the server are built through a new private UserGroupMember._from_server(), which skips the role check and keeps the stored role. Nothing changes in the public API.

What stays the same:

  • UserGroupMember(user=..., role=...) still raises ValueError for NONE and TENANT_ADMIN. The existing tests for this are unchanged and pass.
  • Building a new member from a stored role is still refused (UserGroupMember(user=other, role=stored_member.role) and dataclasses.replace(...) both run the check).
  • update() replaces the whole member list. After get() then update(), the stored member is sent back with the same role id, so saving a group you read does not drop or change that member. Before this fix that round trip could not happen, because get() raised.

Other code that uses a member's role: update(), create() and add_members() only pass member.role.uid to the server, and __hash__/__eq__ compare ids. None of them assume the role is assignable, so they work with a stored member as they do with any other.

Tests

New unit tests in libs/labelbox/tests/unit/schema/test_user_group.py, each run for a stored role of None and of Tenant Admin (10 cases):

  • get_user_groups() returns both groups and the member with its stored role.
  • get() returns the member with its stored role.
  • list_members() returns the member with its stored role.
  • get() then update() sends the member back with its stored role, and the read at the end of update() returns it.
  • A stored role still cannot be used to build a new member.

Results:

  • Without the fix: 10 failed, 26 passed in test_user_group.py. Every failure is the ValueError above.
  • With the fix: 36 passed in test_user_group.py; full unit suite (pytest tests/unit) 510 passed.
  • mypy src: no issues. ruff format --check and ruff check on the changed files: clean.

Integration tests were not run locally (they need an API key); CI runs them.

Suggested changelog line for the next release

Fixed: UserGroup.get_user_groups(), UserGroup.get() and UserGroup.list_members() no longer raise ValueError when a group has a member whose stored role is None or Tenant Admin. The member is returned with its stored role.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

All Submissions

  • Have you followed the guidelines in our Contributing document?
  • Have you provided a description?
  • Are your changes properly formatted?

Changes to Core Features

  • Have you written new tests for your core changes, as applicable?
  • Have you successfully run tests with your changes locally?
  • Have you updated any code comments, as applicable?

🤖 Generated with Claude Code

…role

UserGroupMember refuses the roles NONE and TENANT_ADMIN, which is right for
members a caller builds. The same check also ran when the SDK built members
from a server response, so one stored member with such a role made
UserGroup.get_user_groups(), get(), list_members() and the reads at the end
of create() and update() raise ValueError.

Members read from the server are now built without the role check and keep
the role stored for them. Building a member with one of these roles is still
refused.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mnoszczak

Copy link
Copy Markdown
Contributor Author

CI note: the failing jobs ("Integration Testing" and "Unit && Data Testing" on every Python version) all fail the same way, with AuthenticationError: Invalid API key on each test that calls the API. The key CI uses for the staging test workspace is being refused, so this is not caused by the change here. The unit tests for this change pass (see the description). These jobs need a rerun once the CI key is renewed.

@mnoszczak
mnoszczak marked this pull request as ready for review November 25, 2026 08:09
@mnoszczak
mnoszczak requested a review from a team as a code owner November 25, 2026 08:09
@mnoszczak
mnoszczak merged commit f0e6193 into develop Nov 25, 2026
13 of 23 checks passed
@mnoszczak
mnoszczak deleted the mnoszczak/plt-3830-list-groups-none-role branch November 25, 2026 08:44

This branch was previously deployed

1 inactive deployment
Test-PyPI — 23bd16f7 Deployed Nov 17, 2026 by mnoszczak via test-pypi #2579
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants